//
//  FFBankcardListCell.m
//  LLWallet
//
//  Created by tt on 2020/9/9.
//

#import "FFBankcardListCell.h"
#import <Masonry/Masonry.h>

@implementation FFBankcardListModel

- (Class)cell {
    return FFBankcardListCell.class;
}

- (NSNumber *)showArrow {
    return @(false);
}
@end

@interface FFBankcardListCell ()

@property(nonatomic,strong) UIImageView *bankLogoImgView;
@property(nonatomic,strong) UIImageView *bankBgImgView; // 银行背景图
@property(nonatomic,strong) UILabel *bankNameLbl;
@property(nonatomic,strong) UILabel *bankTypeLbl;
@property(nonatomic,strong) UILabel *bankcardLbl;

@end

@implementation FFBankcardListCell

+ (CGSize)sizeForModel:(WKFormItemModel *)model {
    return CGSizeMake(WKScreenWidth, 110.0f);
}

- (void)setupUI {
    [super setupUI];
    [self setBackgroundColor:[UIColor clearColor]];
    [self.contentView addSubview:self.bankBgImgView];
    
    [self.bankBgImgView addSubview:self.bankLogoImgView];
    [self.bankBgImgView addSubview:self.bankNameLbl];
    [self.bankBgImgView addSubview:self.bankTypeLbl];
    [self.bankBgImgView addSubview:self.bankcardLbl];
}

- (UIImageView *)bankBgImgView {
    if(!_bankBgImgView) {
        _bankBgImgView = [[UIImageView alloc] init];
        [_bankBgImgView setBackgroundColor:[UIColor whiteColor]];
        _bankBgImgView.contentMode = UIViewContentModeScaleAspectFill;
        _bankBgImgView.layer.masksToBounds = YES;
        _bankBgImgView.layer.cornerRadius = 4.0f;
    }
    return _bankBgImgView;
}

- (UIImageView *)bankLogoImgView {
    if(!_bankLogoImgView) {
        _bankLogoImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 45.0f, 45.0f)];
    }
    return _bankLogoImgView;
}

- (UILabel *)bankcardLbl {
    if(!_bankcardLbl) {
        _bankcardLbl = [[UILabel alloc] init];
        [_bankcardLbl setFont:[[WKApp shared].config appFontOfSizeSemibold:22.0f]];
        _bankcardLbl.textColor = [UIColor blackColor];
    }
    return _bankcardLbl;
}

- (UILabel *)bankTypeLbl {
    if(!_bankTypeLbl) {
        _bankTypeLbl = [[UILabel alloc] init];
        [_bankTypeLbl setFont:[[WKApp shared].config appFontOfSize:15.0f]];
        [_bankTypeLbl setTextColor:[WKApp shared].config.tipColor];
    }
    return _bankTypeLbl;
}
- (UILabel *)bankNameLbl {
    if (!_bankNameLbl) {
        _bankNameLbl = [[UILabel alloc] init];
        [_bankNameLbl setFont:[[WKApp shared].config appFontOfSizeMedium:17.0f]];
        _bankNameLbl.textColor = [UIColor blackColor];
    }
    return _bankNameLbl;
}

- (void)refresh:(FFBankcardListModel *)model {
    [super refresh:model];
    
    if(!model.bankLogo || [model.bankLogo isEqualToString:@""]) {
        self.bankLogoImgView.image = [self imageName:@"default_bank"];
    }else{
        [self.bankLogoImgView setImageWithURL:[NSURL URLWithString:model.bankLogo]];
    }
    
    [self.bankBgImgView setImageWithURL:[NSURL URLWithString:model.bankBg]];
    self.bankNameLbl.text = model.bankName;
    self.bankTypeLbl.text = model.bankType;
    self.bankcardLbl.text = model.bankcard;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.bankBgImgView.lim_size = CGSizeMake(self.lim_width - 40.0f, self.lim_height);
    self.bankBgImgView.lim_left = 20.0f;
    
    self.bankLogoImgView.lim_left = 15.0f;
    self.bankLogoImgView.lim_top = 10.0f;
    
    [self.bankNameLbl sizeToFit];
    self.bankNameLbl.lim_top = self.bankLogoImgView.lim_top + 2.0f;
    self.bankNameLbl.lim_left = self.bankLogoImgView.lim_right + 10.0f;
    
    [self.bankTypeLbl sizeToFit];
    self.bankTypeLbl.lim_top = self.bankNameLbl.lim_bottom + 4.0f;
    self.bankTypeLbl.lim_left = self.bankNameLbl.lim_left;
    
    [self.bankcardLbl sizeToFit];
    self.bankcardLbl.lim_left = self.bankLogoImgView.lim_left;
    self.bankcardLbl.lim_top = self.bankLogoImgView.lim_bottom + 20.0f;
}

-(UIImage*) imageName:(NSString*)name {
    return [[WKApp shared] loadImage:name moduleID:@"LLWallet"];
}

@end


@implementation WKBiAddressListModel

- (Class)cell {
    return WKBiAddressListCell.class;
}

- (NSNumber *)showArrow {
    return @(false);
}
@end

@interface WKBiAddressListCell ()

@property(nonatomic,strong) UIImageView *bankLogoImgView;
@property(nonatomic,strong) UIImageView *bankBgImgView; // 银行背景图
@property(nonatomic,strong) UILabel *bankNameLbl;
@property(nonatomic,strong) UILabel *bankTypeLbl;
@property(nonatomic,strong) UILabel *bankcardLbl;

@end

@implementation WKBiAddressListCell

+ (CGSize)sizeForModel:(WKFormItemModel *)model {
    return CGSizeMake(WKScreenWidth, 90.0f);
}

- (void)setupUI {
    [super setupUI];
    [self setBackgroundColor:[UIColor clearColor]];
    [self.contentView addSubview:self.bankBgImgView];
    
//    [self.bankBgImgView addSubview:self.bankLogoImgView];
    [self.bankBgImgView addSubview:self.bankNameLbl];
    [self.bankBgImgView addSubview:self.bankTypeLbl];
//    [self.bankBgImgView addSubview:self.bankcardLbl];
    
    [self.bankBgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.top.bottom.mas_equalTo(0);
    }];
    
    [self.bankNameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(16);
    }];
    
    [self.bankTypeLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.bottom.mas_equalTo(-16);
    }];
}

- (UIImageView *)bankBgImgView {
    if(!_bankBgImgView) {
        _bankBgImgView = [[UIImageView alloc] init];
        [_bankBgImgView setBackgroundColor:[WKApp shared].config.cellBackgroundColor];
        _bankBgImgView.contentMode = UIViewContentModeScaleAspectFill;
        _bankBgImgView.layer.masksToBounds = YES;
        _bankBgImgView.layer.cornerRadius = 4.0f;
    }
    return _bankBgImgView;
}

- (UIImageView *)bankLogoImgView {
    if(!_bankLogoImgView) {
        _bankLogoImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 45.0f, 45.0f)];
    }
    return _bankLogoImgView;
}

- (UILabel *)bankcardLbl {
    if(!_bankcardLbl) {
        _bankcardLbl = [[UILabel alloc] init];
        [_bankcardLbl setFont:[[WKApp shared].config appFontOfSizeSemibold:22.0f]];
        _bankcardLbl.textColor = [UIColor blackColor];
    }
    return _bankcardLbl;
}

- (UILabel *)bankTypeLbl {
    if(!_bankTypeLbl) {
        _bankTypeLbl = [[UILabel alloc] init];
        _bankcardLbl.numberOfLines = 2;
        [_bankTypeLbl setFont:[[WKApp shared].config appFontOfSize:15.0f]];
        [_bankTypeLbl setTextColor:[UIColor grayColor]];
    }
    return _bankTypeLbl;
}
- (UILabel *)bankNameLbl {
    if (!_bankNameLbl) {
        _bankNameLbl = [[UILabel alloc] init];
        [_bankNameLbl setFont:[[WKApp shared].config appFontOfSizeMedium:17.0f]];
        _bankNameLbl.textColor = [WKApp shared].config.defaultTextColor;
    }
    return _bankNameLbl;
}

- (void)refresh:(WKBiAddressListModel *)model {
    [super refresh:model];
    
//    if(!model.bankLogo || [model.bankLogo isEqualToString:@""]) {
//        self.bankLogoImgView.image = [self imageName:@"default_bank"];
//    }else{
//        [self.bankLogoImgView setImageWithURL:[NSURL URLWithString:model.bankLogo]];
//    }
    
//    [self.bankBgImgView setImageWithURL:[NSURL URLWithString:model.logo]];
    self.bankNameLbl.text = model.symbol;
    self.bankTypeLbl.text = model.address;
//    self.bankcardLbl.text = model.bankcard;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
//    [self.bankTypeLbl mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.top.mas_equalTo(16);
//    }];
//    
//    [self.bankNameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(16);
//        make.right.bottom.mas_equalTo(-16);
//    }];
}

-(UIImage*) imageName:(NSString*)name {
    return [[WKApp shared] loadImage:name moduleID:@"LLWallet"];
}

@end
